<template>
    <div id="detail">
        <van-nav-bar
            title="详情页"
            left-text="返回"
            right-text="..."
            left-arrow
            @click-left="$router.go(-1)"
        />

        <div class="header">
            <img src="shopinfo.info.picUrl" alt="">
            <h3>{{shopinfo.info.name}}</h3>
            <van-search v-model="value" placeholder="搜索"/>
            <span>点餐</span>
            <span>评价</span>
            <span>商家</span>
            <div class="right" v-if="isCollect" @click="cancel_collect(shopinfo.info)" style="color:red">❤</div>
            <div class="right" v-else @click="collect(shopinfo.info)">❤</div>
        </div>

    <div class="box">
      <div class="left">
        <van-sidebar v-model="currentIndex">
          <van-sidebar-item  v-for="(item,index) in shopinfo.taglist" :key="index" :title="item.name" />
        </van-sidebar>
      </div>
      <div class="right">
        <div class="good" v-for="(item,index) in shopinfo.taglist && shopinfo.taglist[currentIndex].goodlist" :key="index">
          <div class="imgbox">
            <img :src="item.picture" alt="">
          </div>
          <div class="text">
            <div class="up">
              <div class="name">{{item.name}}</div>
              <div class="desc">{{item.month_saled_content}}</div>
            </div>
            <div class="down">
              <div class="price">¥{{item.min_price}}</div>
              <div class="opes">
                <button>+</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    </div>
</template>

<script>
import { shop_shopinfo } from '@/utils/api';
import { mapActions, mapGetters, mapMutations, mapState } from 'vuex';
import { Dialog } from 'vant';
export default {
    data() {
        return {
            value: '',
            currentIndex:0,
            shopinfo:'',
        };
    },
    computed:{
        ...mapState('collect',['collectlist']),
        ...mapGetters([]),
        isCollect(){
            var index=this.collectlist.findIndex((item)=>{
                return item.mtWmPoiId==this.shopinfo.mtWmPoiId;
            })
            return index !==-1;
        }
    },
    methods:{
        ...mapMutations('collect',['collect','cancel_collect']),
        ...mapActions([])
    },
    mounted(){
        shop_shopinfo({id:this.$route.params.id}).then((res)=>{
            console.log(res.data)
            if(res.data.shopinfo){
                this.shopinfo=res.data.shopinfo;
            }else{
                Dialog.alert({
                    title: '提示',
                    message: '该店铺已倒闭!'
                }).then(()=>{
                    this.$router.go(-1);
                })
            }
        })
    }
};
</script>

<style>
.header{
    background: aliceblue;
    height: 120px;
    position: relative;
}
.header h3{
    margin: 0 15px;
}
.header .van-search{
    width: 100px;
    border-radius: 10px;
    background: aliceblue;
    position: absolute;
    bottom: 0;
}
.header span:nth-child(4){
    position: absolute;
    bottom: 14%;
    left: 29%;
}
.header span:nth-child(5){
    position: absolute;
    bottom: 14%;
    left: 45%;
}
.header span:nth-child(6){
    position: absolute;
    bottom: 14%;
    left: 60%;
}
.header .right{
    position: absolute;
    right: 10%;
    color: white;
    font-size: 30px;
    top: 30%;
}
.box{
  display: flex;
}
.box .left{
    width: 80px;
  }
.box .right{
    flex:1;
}
.box .right .good{
      display: flex;
      margin: 10px;
}
.box .right .good .imgbox{
        width: 80px;
        margin-right: 10px;
}
.box .right .good .imgbox   img{
          width: 100%;
        }
 .box .right .good  .text{
        flex:1;
        font-size: 12px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
 }
 .box .right .good  .text  .down{
          display: flex;
          justify-content: space-between;
        }
</style>